//
//  JMNavigationController.m
//  jiMuOperate
//
//  Created by 翁仪 on 16/4/15.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMNavigationController.h"
#import "UIBarButtonItem+Extension.h"

@interface JMNavigationController ()

@end

int const NAVBARHEIGHT = 54;
@implementation JMNavigationController
-(void)viewDidLoad
{
    [super viewDidLoad];
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav--bar"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],
NSForegroundColorAttributeName:[UIColor whiteColor]}];
}


//
//- (void)layoutSubviews
//{
//    self.navigationBar.frame = CGRectMake(0, 0, SCREEN_WIDTH, NAVBARHEIGHT);
//}


//+ (void)initialize
//{
//    
//    // 通过appearance对象能修改整个项目中所有UIBarButtonItem的样式
//    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
//    // 设置普通状态的文字属性
//    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
//    textAttrs[UITextAttributeTextColor] = [UIColor orangeColor];
//    textAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15];
//    [appearance setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
//    
//    // 设置高亮状态的文字属性
//    NSMutableDictionary *highTextAttrs = [NSMutableDictionary dictionary];
//    highTextAttrs[UITextAttributeTextColor] = [UIColor redColor];
//    highTextAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15];
//    [appearance setTitleTextAttributes:highTextAttrs forState:UIControlStateHighlighted];
//    
//    // 设置不可用状态(disable)的文字属性
//    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
//    disableTextAttrs[UITextAttributeTextColor] = [UIColor lightGrayColor];
//    disableTextAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15];
//    [appearance setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
//}

/**
 *  能拦截所有push进来的子控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 如果现在push的不是栈底控制器(最先push进来的那个控制器)
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"aut_ico_back" highImageName:@"aut_ico_back" target:self action:@selector(back)];
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_more" highImageName:@"navigationbar_more_highlighted" target:self action:@selector(more)];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}

- (void)more
{
    [self popToRootViewControllerAnimated:YES];
}

@end
